#ifndef Eoncder_H
#define Eoncder_H

//可调旋钮器
//用法:
//主循环之前调用: EncoderInit();
//主循环内调用:
//	EncoderMain();
//旋钮检测时钟源,2ms定时调用: EncoderClock();

#define GPIO_ReadEncoderA gpio_get_level(IO_EncodeA) //digitalRead(IO_EncodeA)	//GPIO_ReadBit(EncodeA)
#define GPIO_ReadEncoderB gpio_get_level(IO_EncodeB) //digitalRead(IO_EncodeB) //GPIO_ReadBit(EncodeB)
#define GPIO_ReadEncoderKey gpio_get_level(IO_EncodeKey) //digitalRead(IO_EncodeKey) //GPIO_ReadBit(EncodeKey)
#define Encoder_Pin_Sel  ((1ULL<<IO_EncodeA) | (1ULL<<IO_EncodeB) | (1ULL<<IO_EncodeKey))


typedef struct
{
	uint8_t ASamping;
	uint8_t BSamping;
	uint8_t ParseEnable;
	uint8_t IsKey;
	uint8_t IsLongKey;

	uint8_t IsLongKeyCount; //间隔1s,检测3次有效代表长按有效
	uint8_t TurnRCount;
	uint8_t TurnLCount;
	uint8_t KeyUpCount;
	uint8_t KeyDownCount;
	uint8_t IsTurnR;
	uint8_t IsTurnL;
}EncoderParam_S;
extern EncoderParam_S EncoderParam;

void EncoderInit(void);
void EncoderMain(void);
void EncoderClock(void);

//函数接口
void (*Encoder_Key_Handler)(void);
void (*Encoder_LongKey_Handler)(void);
void (*Encoder_TurnR_Handler)(void);
void (*Encoder_TurnL_Handler)(void);

#endif
